#include <iostream>
#include <algorithm>
using namespace std;

struct data{
	int v;
	int w;
};

data src[11];


bool cmp(data a,data b)
{
	return a.v>b.v;
}

int main()
{
	int t;
	while(cin>>t){
		while(t--){
			int x,y;
			cin>>x>>y;
			for(int i=0;i<x;i++) cin>>src[i].v>>src[i].w;
			sort(src,src+x,cmp);
			int position=0;
			int sum=0;
			while(y>0){
				if(src[position].w>y){
					sum=sum+src[position].v*y;
					break;
				}
				else{
					y=y-src[position].w;
					sum=sum+src[position].v*src[position].w;
					position++;
				}
			}
			cout<<sum<<endl;
		}
	}
}
